/**
 * Copyright (c) Software Institute of PKU
 * All rights reserved. 
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 */
package edu.pku.sei.modeler.ui.ccp;

import java.util.List;

import org.eclipse.gef.ui.actions.Clipboard;
import org.eclipse.gef.ui.actions.SelectionAction;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PlatformUI;

import edu.pku.sei.modeler.edit.parts.DiagramEditPart;

/**
 * @author zl
 *
 */
public class CutAction extends SelectionAction {
	private Clipboard clipboard = null;
	private List selectionList = null;
	
	public CutAction(IWorkbenchPart part) {
		super(part);
		this.setText(CCPConstants.CUT_NAME);
		this.setDescription(CCPConstants.CUT_DESC);
		ISharedImages si = PlatformUI.getWorkbench() .getSharedImages(); 
		this.setImageDescriptor(si.getImageDescriptor(ISharedImages.IMG_TOOL_CUT));
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.gef.ui.actions.WorkbenchPartAction#calculateEnabled()
	 */
	@Override
	protected boolean calculateEnabled() {
		selectionList = this.getSelectedObjects();
		if (selectionList.isEmpty()||
				(selectionList.size()==1&&selectionList.get(0) instanceof DiagramEditPart))return false;
		return true;
	}

	public Clipboard getClipboard() {
		if (clipboard == null) {
			clipboard = Clipboard.getDefault();
		}
		return clipboard;
	}

	public void run() {
		getClipboard().setContents(selectionList);
	}
}
